﻿using Microsoft.Win32;
using MVVM_Learning.Command;
using MVVM_Learning.Models;
using MVVM_Learning.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace MVVM_Learning.ViewModels
{
    internal class MainWindowViewModel:Notificationobject
    {
        private double input1; // _表示改变量是私有的
        public double Input1
        {
            get { return input1; }
            set 
            {   
                input1 = value;
                this.RaisePropertyChanged("Input1");
            } 
        }

        private double input2;
        public double Input2
        {
            get { return input2; }
            set 
            {   
                input2 = value;
                this.RaisePropertyChanged("Input2");
            }
        }

        private double result;

        public double Result 
        {
            get { return result; }
            set 
            {   
                result = value;
                this.RaisePropertyChanged("Result");
            }
        }

        public DelegateCommand AddCommand { get; set; }
        public DelegateCommand SaveCommand { get; set; }
        public DelegateCommand JumpCommand { get; set; }


        private void Add(object parameter)
        {
            this.Result = this.Input1 + this.Input2;
        }

        private void Save(object parameter)
        {
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.ShowDialog();
        }

        private void Jump(object parameter)
        {
            RestaurantView RV = new RestaurantView();
            RV.Show();
            Application.Current.MainWindow.Close();
        }

        public MainWindowViewModel() 
        {
            this.AddCommand = new DelegateCommand();
            // 相当于将Add方法与AddCommand的ExecuteAction委托关联起来
            this.AddCommand.ExecuteAction = new Action<object>(this.Add); 
            this.SaveCommand = new DelegateCommand();
            // 相当于将Save方法与SaveCommand的ExecuteAction委托关联起来
            this.SaveCommand.ExecuteAction = new Action<object>(this.Save);
            this.JumpCommand = new DelegateCommand();
            // 相当于将Save方法与SaveCommand的ExecuteAction委托关联起来
            this.JumpCommand.ExecuteAction = new Action<object>(this.Jump);
        }
    }
}
